#include "MySqlConnPool/include/OCDatabaseMapper.h"
OCDatabaseMapper* OCDatabaseMapper::instance=nullptr;



OCDatabaseMapper *OCDatabaseMapper::getInstance()
{
    if(instance==nullptr)
    {
        instance=new OCDatabaseMapper();
    }
    return instance;
}

void OCDatabaseMapper::initMapper()
{
    auto user_conn_set=SqlSetManager::getInstance()->getSet("user");
    auto user_conn=user_conn_set->acquire();
    auto res=user_conn->execute("SELECT * FROM dbinfo");
    while(res->next())
    {
        oc_db.insert({res->getString(1),res->getString(2)});
    }
}

void OCDatabaseMapper::addOC(const std::string oc, const std::string db_name)
{
    oc_db.insert({oc,db_name});
}

void OCDatabaseMapper::updateOC(const std::string oldoc,const std::string newoc)
{
    std::string db_name=oc_db[oldoc];
    oc_db.erase(oldoc);
    oc_db.insert({newoc,db_name});
}

void OCDatabaseMapper::removeOC(const std::string oc)
{
    oc_db.erase(oc);
}

std::string OCDatabaseMapper::getDB(std::string oc)
{
    return oc_db[oc];
}

std::unordered_map<std::string, std::string>& OCDatabaseMapper::getMap()
{
    return oc_db;
}

OCDatabaseMapper::OCDatabaseMapper()
{

}
